package pers.qianyu.month_202011.date_20201112;

import java.util.*;

/**
 * 46. 全排列
 * https://leetcode-cn.com/problems/permutations/
 * @date 2020年11月12日20:26:24
 */
public class Permute {

    private List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        recur(nums, new ArrayList<>());
        return result;
    }

    private void recur(int[] nums, List<Integer> list) {
        if (list.size() == nums.length) {
            result.add(new ArrayList<>(list));
            return;
        }
        for (int num : nums) {
            if (list.contains(num)) {
                continue;
            }
            list.add(num);
            recur(nums, list);
            list.remove(Integer.valueOf(num));
        }
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        List<List<Integer>> res = new Permute().permute(arr);
        res.forEach(System.out::println);
    }
}